﻿using System;

namespace UniRx.Operators
{
	// Token: 0x02000324 RID: 804
	internal class ThrowObservable<T> : OperatorObservableBase<T>
	{
		// Token: 0x060010C4 RID: 4292 RVA: 0x0004D2FC File Offset: 0x0004B6FC
		public ThrowObservable(Exception error, IScheduler scheduler) : base(scheduler == Scheduler.CurrentThread)
		{
			this.error = error;
			this.scheduler = scheduler;
		}

		// Token: 0x060010C5 RID: 4293 RVA: 0x0004D31C File Offset: 0x0004B71C
		protected override IDisposable SubscribeCore(IObserver<T> observer, IDisposable cancel)
		{
			observer = new ThrowObservable<T>.Throw(observer, cancel);
			if (this.scheduler == Scheduler.Immediate)
			{
				observer.OnError(this.error);
				return Disposable.Empty;
			}
			return this.scheduler.Schedule(delegate()
			{
				observer.OnError(this.error);
				observer.OnCompleted();
			});
		}

		// Token: 0x040009DD RID: 2525
		private readonly Exception error;

		// Token: 0x040009DE RID: 2526
		private readonly IScheduler scheduler;

		// Token: 0x02000325 RID: 805
		private class Throw : OperatorObserverBase<T, T>
		{
			// Token: 0x060010C6 RID: 4294 RVA: 0x0004D38D File Offset: 0x0004B78D
			public Throw(IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
			{
			}

			// Token: 0x060010C7 RID: 4295 RVA: 0x0004D398 File Offset: 0x0004B798
			public override void OnNext(T value)
			{
				try
				{
					this.observer.OnNext(value);
				}
				catch
				{
					base.Dispose();
					throw;
				}
			}

			// Token: 0x060010C8 RID: 4296 RVA: 0x0004D3D4 File Offset: 0x0004B7D4
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x060010C9 RID: 4297 RVA: 0x0004D40C File Offset: 0x0004B80C
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}
		}
	}
}
